package com.youth.spring.test.framework;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.ContextHierarchy;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.TransactionConfiguration;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.web.context.WebApplicationContext;

import com.youth.entity.School;
import com.youth.service.ISchoolService;

/**
 * Spring MVC测试框架详解——服务端测试(集成web环境测试)
 * 临时
 * @author xkli
 * 推荐阅读：http://jinnianshilongnian.iteye.com/blog/2004660
 */
@RunWith(SpringJUnit4ClassRunner.class)  
@WebAppConfiguration(value = "src/main/webapp")  
//当然 你可以声明一个事务管理 每个单元测试都进行事务回滚 无论成功与否  
@TransactionConfiguration(defaultRollback = true) 
@ContextHierarchy({
        @ContextConfiguration(name = "parent", locations = "classpath:applicationContext.xml"),  
        @ContextConfiguration(name = "child", locations = "classpath:springMVC-servlet.xml")  
}) 
public class SpringTestFramework {
	 	
		@Autowired  
	 	ISchoolService schoolService;
	 	
	 	@Autowired 
	 	private WebApplicationContext wac;  

	 	@Test
	 	public void test() {
	 		School school = schoolService.getSchool();
	 		System.out.println(school.getName());
	 	}
	    
	    
}
